package com.db;

import com.excel.read.DBTable;

public class ForeignKey {

	private String fkName;
	private String fkTable;
	/**
	 * 关联到的表
	 */
	private String toTableName;
	/**
	 * 关联到的表字段
	 */
	private String toField;
	
	
	/**
	 * 关联到的表
	 * @return
	 */
	private DBTable toTable;
	
	
	private DBTable fromTable;
	
	
	public String getFkName() {
		return fkName;
	}
	public void setFkName(String fkName) {
		this.fkName = fkName;
	}
	public String getFkTable() {
		return fkTable;
	}
	public void setFkTable(String fkTable) {
		this.fkTable = fkTable;
	}
	public String getToTableName() {
		return toTableName;
	}
	public void setToTableName(String toTableName) {
		this.toTableName = toTableName;
	}
	public String getToField() {
		return toField;
	}
	public void setToField(String toField) {
		this.toField = toField;
	}
	
	public void setToTable(DBTable toTable) {
		this.toTable = toTable;
	}
	public DBTable getToTable() {
		return toTable;
	}
	public DBTable getFromTable() {
		return fromTable;
	}
	public void setFromTable(DBTable fromTable) {
		this.fromTable = fromTable;
	}
	
	public String getQuerySQL() {
		
		StringBuffer sbf = new StringBuffer();
		sbf.append("select ");
		sbf.append(toTable.getPk().getName());
		sbf.append(" from ");
		sbf.append(toTable.getName());
		sbf.append(" where ");
		sbf.append(toField);
		sbf.append(" = ?");
		return sbf.toString();
	}
	
	

}
